{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "332126f9-3524-4223-bcc6-24b9818b77b5",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from mythic import mythic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "abfa531f-5e7a-400b-910c-92a62106ccbe",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "mythic_instance = await mythic.login(\n",
    "        username=\"mythic_admin\",\n",
    "        password=\"mythic_password\",\n",
    "        server_ip=\"mythic_nginx\",\n",
    "        server_port=7443,\n",
    "        timeout=-1\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "42edcddf-b739-4eb5-ad5f-443c72b748de",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# ################ Provide custom attributes for pre-built query ################\n",
    "custom_attributes = \"\"\"\n",
    "host\n",
    "user\n",
    "payload {\n",
    "    id\n",
    "    uuid\n",
    "}\n",
    "\"\"\"\n",
    "result = await mythic.get_all_callbacks(\n",
    "    mythic=mythic_instance, custom_return_attributes=custom_attributes\n",
    ")\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "70f9a5c4-f8d2-4b94-b133-2c43da08bc21",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# ################ Custom subscription ################\n",
    "my_custom_process_subscription = \"\"\"\n",
    "subscription myFilemetaSubscription {\n",
    "     filemeta_stream(cursor: {initial_value: {id: 1}}, batch_size: 1) {\n",
    "         filename_utf8\n",
    "         full_remote_path_utf8\n",
    "         host\n",
    "         complete\n",
    "         id\n",
    "         md5\n",
    "         sha1\n",
    "         timestamp\n",
    "         task {\n",
    "             callback {\n",
    "                 agent_callback_id\n",
    "                 payload {\n",
    "                     uuid\n",
    "                     os\n",
    "                     payloadtype {\n",
    "                         name\n",
    "                     }\n",
    "                 }\n",
    "             }\n",
    "         }\n",
    "     }\n",
    " }\n",
    " \"\"\"\n",
    "async for data in mythic.subscribe_custom_query(\n",
    "     mythic=mythic_instance, query=my_custom_process_subscription, timeout=10\n",
    " ):\n",
    "    # do something with the data\n",
    "    print(f\"[*] Got Process data:\\n{data}\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40a30e88-6e31-4fed-a60c-c6bdcba0749f",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# ################ Custom query ################\n",
    "operation = await mythic.execute_custom_query(\n",
    "    mythic=mythic_instance,\n",
    "    query=\"\"\"\n",
    "    query specificOperation{\n",
    "        operation(where: {name: {_eq: \"Operation Chimera\"}}) {\n",
    "            id\n",
    "            name\n",
    "            operators {\n",
    "                id\n",
    "                username\n",
    "            }\n",
    "        }\n",
    "    }\n",
    "\"\"\",\n",
    ")\n",
    "print(operation)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "654b1348-cf5f-4b2c-9d01-bed63d613a6b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# ################ Custom query with variables ################\n",
    "operation = await mythic.execute_custom_query(\n",
    "    mythic=mythic_instance,\n",
    "    query=\"\"\"\n",
    "    query specificOperation($operation_name: String!){\n",
    "        operation(where: {name: {_eq: $operation_name}}) {\n",
    "            id\n",
    "            name\n",
    "            operators {\n",
    "                id\n",
    "                username\n",
    "            }\n",
    "        }\n",
    "    }\n",
    "\"\"\",\n",
    "    variables={\"operation_name\": \"Operation Chimera\"}\n",
    ")\n",
    "print(operation)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "076c3a79-b433-4d51-a9e7-0ad89537a8d9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
